package es.upm.gib.mappingAPI2;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * This class contains some custom data of the mapping
 */
public class CustomData implements Serializable{

    //=======================================================================
    //ATTRIBUTES
    //=======================================================================

    /**
     * values of the custom data
     */
    private Map<String, String> values;

    //=======================================================================
    // CONSTRUCTORS
    //=======================================================================

    /**
     * Constructor
     */
    public CustomData(){
        this.values = new HashMap<String, String>();
    }

    public CustomData(Map<String, String> values){
        this.values = values;
    }

    //=======================================================================
    // PUBLIC METHODS
    //=======================================================================

    /**
     * Retrieves values of the custom data
     * @return custom data values
     */
    public Map<String, String> getData(){
        return values;
    }

    /**
     * Add new value to the custom Data
     * @param key key of custom data
     * @param value value of custom data
     */
    public void addValue(String key, String value){
        values.put(key, value);
    }

    /**
     * Retrieves true if the element exists in the custom data
     * @param key value of the element
     * @return true if the element exists, false otherwise
     */
    public boolean contains(String key){
        return values.containsKey(key);
    }

    /**
     * Remove the input key element
     * @param key value of the element to remove
     */
    public void remove(String key){
        values.remove(key);
    }

    /**
     * Retrieves the element requested by the input key
     * @param key value of the requested element
     * @return the element requested
     */
    public String get(String key){
        if (values.containsKey(key)){
            return values.get(key);
        }
        else{
            return null;
        }
    }

    /**
     * Set the input map of data
     * @param data data to store
     */
    public void setData(Map<String, String> data){
        this.values = new HashMap<String, String>(data);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CustomData that = (CustomData) o;

        if (!values.equals(that.values)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return values.hashCode();
    }
}
